/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package example;

public class ItemList {
   Item first, last;
   public ItemList(){}
   public ItemList(Item item) {
       first=item; last=item;
   }
   public Item first() { return first; }
   public Item last() { return last; }
   public void add(Item item) {
       if (first==null) {
           first=item; last=first;
           return;
       }
       last.next=item; last=item;
   }
   public void remove(Item item) {
       if (first==null) return;
       if (item==null) return;
       if (item==last) {
           Item p=first;
           while (p.next!=last) p=p.next;
           p.next=null; last=p;
           return;
       }
       item=item.next;
   }
  public void purge() {
      Item p, q;
      p=first;
      while (p != null) {
         q=p.getNext();
         while (q !=null) {
            if (p.getName().compareTo(q.getName())==0)
               //p.getNext().setNext(q.getNext());
               this.remove(q);
            q=q.getNext();
         }
         p=p.getNext();
      }
  }
}
